<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<link rel="stylesheet" type="text/css" href="../css/bootstrap.min.css">
</head>
<body>
<div style="width: 99%;margin:5px auto;">
<form class="col-xs-12">
	<button id="adminuserlist_btn" type="button" class="btn btn-primary">管理员账号列表接口admin/user/list</button>
 	<div class="bs-example" data-example-id="simple-pre">
	  <pre id="adminuserlist_msg"> </pre>
	</div>
	<hr>
	<!-------------------------------------------------------->
	<select class="form-control" id="role">
	  <option value="ROLE_SALES_DIRECTOR">业务总监</option>
	  <option value="ROLE_SALES">业务员</option>
	</select>
	<input type="text" class="form-control" id="username" placeholder="username" value="13800138000">
	<input type="text" class="form-control" id="password" placeholder="password" value="12345678">
	<input type="text" class="form-control" id="description" placeholder="description" value="李小二">
	<input type="text" class="form-control" id="phone" placeholder="phone" value="13800138000">
	<input type="text" class="form-control" id="email" placeholder="email" value="li@atwulian.com">
	<input type="text" class="form-control" id="remarks" placeholder="remarks" value="李小二">
	<button id="add_btn" type="button" class="btn btn-primary">添加账号接口</button>
	<button id="del_btn" type="button" class="btn btn-primary">删除账号接口</button>
	<hr>
	<!-------------------------------------------------------->
	<input type="text" class="form-control" id="_username" placeholder="username" value="13800138000">
	<br/><br/>
	<select class="form-control" id="_role">
	  <option value="ROLE_SALES_DIRECTOR">业务总监</option>
	  <option value="ROLE_SALES">业务员</option>
	</select>
	<input type="text" class="form-control" id="_description" placeholder="description" value="">
	<input type="text" class="form-control" id="_phone" placeholder="phone" value="">
	<input type="text" class="form-control" id="_email" placeholder="email" value="">
	<input type="text" class="form-control" id="_remarks" placeholder="remarks" value="">
	<button id="get_btn" type="button" class="btn btn-primary">获取账号信息接口</button>
	<button id="edit_btn" type="button" class="btn btn-primary">修改账号信息接口</button>
	<hr>
	<!-------------------------------------------------------->
</form>
</div>
<script type="text/javascript" src="../js/jquery-1.10.2.min.js"></script>
<script type="text/javascript">
$(function(){
	$('#adminuserlist_btn').bind('click', function(){
		$.ajax({
			type: 'post',
			dataType: 'get',
			url: 'http://test.iot.idao.me/account/list',
			beforeSend: function (xhr) {
		        xhr.setRequestHeader("Authorization", localStorage.token);
		    },
			success: function(rsp){
				$('#adminuserlist_msg').html(JSON.stringify(rsp))
			}
		})
	});
	$('#add_btn').bind('click', function(){
		$.ajax({
			type: 'post',
			dataType: 'json',
			url: '../account/add',
			data: {
				username: $('#username').val(), 
				password: $('#password').val(), 
				description: $('#description').val(), 
				phone: $('#phone').val(), 
				email: $('#email').val(), 
				remarks: $('#remarks').val(), 
				role: $('#role').val()
			},
			beforeSend: function (xhr) {
		        xhr.setRequestHeader("Authorization", localStorage.token);
		    },
			success: function(rsp){
				if(rsp.success)
					alert(rsp.result)
				else
					alert(rsp.resultMsg)
			}
		})
	});
	$('#get_btn').bind('click', function(){
		$.ajax({
			type: 'post',
			dataType: 'json',
			url: '../account/get',
			data: {
				username: $('#username').val()
			},
			beforeSend: function (xhr) {
		        xhr.setRequestHeader("Authorization", localStorage.token);
		    },
			success: function(rsp){
				if(rsp.success){
					$('#_description').val(rsp.result.description), 
					$('#_phone').val(rsp.result.phone), 
					$('#_email').val(rsp.result.email), 
					$('#_remarks').val(rsp.result.remarks), 
					$('#_role').val(rsp.result.role)
				}else{
					alert(rsp.resultMsg)
				}
			}
		})
	});
	$('#edit_btn').bind('click', function(){
		$.ajax({
			type: 'post',
			dataType: 'json',
			url: '../account/edit',
			data: {
				username: $('#_username').val(), 
				password: $('#_password').val(), 
				description: $('#_description').val(), 
				phone: $('#_phone').val(), 
				email: $('#_email').val(), 
				remarks: $('#_remarks').val(), 
				role: $('#_role').val()
			},
			beforeSend: function (xhr) {
		        xhr.setRequestHeader("Authorization", localStorage.token);
		    },
			success: function(rsp){
				if(rsp.success)
					alert(rsp.result)
				else
					alert(rsp.resultMsg)
			}
		})
	});
	$('#del_btn').bind('click', function(){
		$.ajax({
			type: 'post',
			dataType: 'json',
			url: '../account/del',
			data: {
				username: $('#username').val()
			},
			beforeSend: function (xhr) {
		        xhr.setRequestHeader("Authorization", localStorage.token);
		    },
			success: function(rsp){
				if(rsp.success)
					alert(rsp.result)
				else
					alert(rsp.resultMsg)
			}
		})
	});
})
</script>
</body>
</html>